<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #demo {
            height: 400px;
            width: 512px;
            margin: 100px auto;
            overflow: hidden;
            position: relative;
        }

        #demo span {
            display: inline-block;
            width: 512px;
            height: 200px;
            position: absolute;
        }

        #demo span:first-child {
            top: 0;
            z-index: 2;
            /*background-color: yellow;*/
        }

        #demo span:nth-child(2) {
            bottom: 0;
            z-index: 2;
            /*background-color: pink;*/
        }

        #img {
            position: absolute;
            top: 0;
        }
    </style>
</head>
<body>
<div id="demo">
    <span id="span1"></span>
    <span id="span2"></span>
    <img src="img/mi.png" alt="" id="img">
</div>
<script>
    var img = document.getElementById("img");
    var span1 = document.getElementById("span1");
    var span2 = document.getElementById("span2");
    var num = 0;
    var bottom = 0;
    var time;
    var time2;
    span1.onmouseover = function () {
        // alert(11);
        time = setInterval(fn, 10);

        function fn() {
            if (num > -1070) {

                num -= 2;

                console.log(img.style.top = num + "px");
            }else {

                clearInterval(time);
            }
        }
    }
    span1.onmouseout = function () {
        clearInterval(time);
    }
    span2.onmouseover = function () {
        // alert(11);
        time2 = setInterval(fn, 10);

        function fn() {
            if (num < 0) {
                num += 2;
                bottom -= 2;
                console.log(img.style.top = num + "px");
            } else {
                clearInterval(time2);
            }
        }
    }
    span2.onmouseout = function () {
        clearInterval(time2);
    }

</script>
</body>
</html>